import requests from "./request";
import mockRequests from "./mockResquest";

// get 三级菜单数据
export const getCategoryListAPI = () =>
	requests.get("/product/getBaseCategoryList");

// get mock轮播图
export const getBannerListAPI = () => mockRequests.get("/banner");

// get mock floor数据
export const getFloorListAPI = () => mockRequests.get("/floor");

// post 搜索结果
export const postSearchListAPI = (params) =>
	requests({
		url: "/list",
		method: "post",
		data: params,
	});

// -----------------------------------------------

// get 商品详情
export const getDetailAPI = (skuId) =>
	requests({ url: `/item/${skuId}`, method: "get" });
/* 
// mock备用 商品详情数据
export const getDetailAPI = () => mockRequests.get("/item");
 */

// -----------------------------------------------

// post 商品信息到购物车（只返回状态码）
export const postAddToCartAPI = (skuId, skuNum) =>
	requests({
		method: "post",
		url: `/cart/addToCart/${skuId}/${skuNum}`,
	});

// get 获取购物车列表
export const getCartListAPI = () => requests.get("/cart/cartList");

// delete 删除购物车商品
export const deleteCartAPI = (skuId) =>
	requests({
		url: `/cart/deleteCart/${skuId}`,
		method: "delete",
	});

// get 商品选中状态
export const getCheckCartAPI = (skuId, isChecked) =>
	requests(`/cart/checkCart/${skuId}/${isChecked}`);

// -------------------------
// get 验证码
export const sendCodeAPI = (phone) =>
	requests.get(`/user/passport/sendCode/${phone}`);

// post 用户注册 data:phone,password,code
export const userRegisterAPI = (data) =>
	requests({
		method: "post",
		url: "/user/passport/register",
		data,
	});

// post 用户登录 data: phone password
export const userLoginAPI = (data) =>
	requests({ url: "/user/passport/login", method: "post", data });

// get 通过token请求用户信息 无参
export const getUserInfoAPI = () =>
	requests.get("/user/passport/auth/getUserInfo");

// get 退出登录
export const userLogoutAPI = () => requests.get("/user/passport/logout");

// -----------------------------------

// get 获取用户地址信息
/* export const getUserAddressAPI = () =>
requests.get("/user/userAddress/auth/findUserAddressList"); */
export const getUserAddressAPI = () => mockRequests.get("/address");

// get 商品清单数据
export const getShopInfoAPI = () => requests.get("/order/auth/trade");

// post 提交订单
export const postTradeInfo = (tradeNo, data) =>
	requests({
		url: `/order/auth/submitOrder?tradeNo=${tradeNo}`,
		method: "post",
		data,
	});

//get 获取订单支付信息
export const getPayInfoAPI = (orderId) =>
	requests.get(`/payment/weixin/createNative/${orderId}`);

// get 获取订单支付状态
export const getPayStatus = (orderId) =>
	requests.get(`/payment/weixin/queryPayStatus/${orderId}`);

// ------------------------------------------
// get 获取我的订单列表
export const getOrderInfoAPI = (page, limit) =>
	requests.get(`/order/auth/${page}/${limit}`);
